<?php

namespace App\Http\Controllers\Api;

use App\Http\Model\ResponseResult;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class MenuController extends Controller
{
    const MENU_TYPE_LINK = 'link';
    const MENU_TYPE_MENU = 'menu';

    public function __construct()
    {
        $this->middleware(['api-auth', 'permission:admin-web']);
    }

    public function sideMenu()
    {
        return ResponseResult::success($this->getFounderMenu());
    }

    private function getFounderMenu()
    {
        return [
            $this->linkTypeMenu('仪表盘', 'fa-th-large', ['name' => 'Home']),
            $this->menuTypeMenu('用户管理', 'fa-users', [
                $this->menuTypeMenuChildren('用户列表', ['name' => 'Users']),
                $this->menuTypeMenuChildren('角色管理', ['name' => 'Role']),
            ])
        ];
    }

    private function linkTypeMenu(string $label, string $icon, $url)
    {
        return [
            'type' => static::MENU_TYPE_LINK,
            'label' => $label,
            'icon' => $icon,
            'url' => $url
        ];
    }

    private function menuTypeMenu(string $label, string $icon, array $children)
    {
        return [
            'type' => static::MENU_TYPE_MENU,
            'label' => $label,
            'icon' => $icon,
            'menus' => $children
        ];
    }

    private function menuTypeMenuChildren(string $label, $url)
    {
        return [
            'label' => $label,
            'url' => $url
        ];
    }
}
